import { Calendar } from "antd-mobile";
import React, { useState } from "react";
import dayjs from "dayjs";
import { useDispatch } from "react-redux";
import { setDate } from "../../store/home/homeSlice";
import { useNavigate } from "react-router-dom";
const min = new Date();
const max = new Date();
max.setDate(max.getDate() + 15);
// 定义一个名为Login的函数组件
const Cal = () => {
  // 返回一个div元素，内容为Login
  const today = dayjs();
  const today1 = dayjs(new Date().getTime() + 24 * 60 * 60 * 1000);
  const today2 = dayjs(new Date().getTime() + 24 * 60 * 60 * 1000 * 2);
  const dispatch = useDispatch()
  const navigate = useNavigate()
  const onChange = (date) => {
    console.log(date);
    dispatch(setDate(new Date(date).toLocaleDateString()))
    navigate(-1)
  };
  return (
    <div>
      {
        <Calendar
          onChange={onChange}
          selectionMode="single"
          min={min}
          max={max}
          prevMonthButton={<span>上一月</span>}
          nextMonthButton={<span>下一月</span>}
          prevYearButton={<span>上一年</span>}
          nextYearButton={<span>下一年</span>}
          renderLabel={(date) => {
            if (dayjs(date).isSame(today, "day")) return "今天";
            if (dayjs(date).isSame(today1, "day")) return "明天";
            if (dayjs(date).isSame(today2, "day")) return "后天";

            // if (date.getDay() === 0 || date.getDay() === 6) {
            //   return '周末'
            // }
          }}
        />
      }
    </div>
  );
};

export default Cal;
